﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using app.Models;
using AmuTools;
using System.Collections;
using System.Data;
using System.Data.SqlClient;

namespace app.Api
{
    /*
        公用接口
    */
    public class ApiHelpDocument : ApiBase
    {
        public ApiHelpDocument(Controller ctx) : base(ctx) { }

        #region 自定义请求参数
        // 作者
        //string req_author { get { return GetStringParam(new ReqStringParamOption { Name = "author", Level = REQPARAMLEVEL.FREE, DefaultValue = "未命名" }); } }
        #endregion

        public void Do(string action)
        {
            switch (action)
            {
                case "get":
                    {
                        HelpDocument a = G.DB.GetById<HelpDocument>(req_id);
                        ResponseJson(new ObjectResult { data = a });
                        break;
                    }
                case "status": // 设置状态
                    {
                        HelpDocument a = G.DB.GetById<HelpDocument>(req_id);
                        a.status = req_status;
                        G.DB.Update<HelpDocument>(a);
                        ResponseJson(new Result());
                        break;
                    }
                case "add":
                    {
                        HelpDocument a = new HelpDocument();
                        a.content = req_content;
                        a.create_time = DateTimeEx.GetNowTimeStamp();
                        a.title = req_title;
                        a.hd_type = GetStringParam(new ReqStringParamOption { Name = "hd_type" });
                        G.DB.Insert<HelpDocument>(a);
                        ResponseJson(new IDResult { id = a.id });
                        break;
                    }
                case "modify":
                    {
                        HelpDocument a = G.DB.GetById<HelpDocument>(req_id);
                        a.content = req_content;
                        a.create_time = DateTimeEx.GetNowTimeStamp();
                        a.title = req_title;
                        a.hd_type = GetStringParam(new ReqStringParamOption { Name = "hd_type" });
                        G.DB.Update<HelpDocument>(a);
                        ResponseJson(new Result());
                        break;
                    }
                case "delete":
                    {
                        G.DB.Delete<HelpDocument>(req_id);
                        ResponseJson(new Result());
                        break;
                    }
                default: break;
            }
        }

    }
}